package cn.zakrov.sbs002.controller;

import cn.zakrov.sbs002.entity.JsonResult;
import cn.zakrov.sbs002.entity.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/jsonresult")
public class JsonResultController {
    @RequestMapping("/user")
    public JsonResult<User> getUser() {
        User user = new User(1L, "Zakrov", "123456");
        return new JsonResult<>(user);
    }

    @RequestMapping("/list")
    public JsonResult<List<User>> getUserList() {
        List<User> userList = new ArrayList<>();
        User user1 = new User(1L, "Zakrov", "123456");
        User user2 = new User(2L, "Noir", "223456");
        userList.add(user1);
        userList.add(user2);
        return new JsonResult<>(userList);
    }

    @RequestMapping("/map")
    public JsonResult<Map<String, Object>> getMap() {
        Map<String, Object> map = new HashMap<>();
        User user = new User(1L, "Zakrov", "123456");
        map.put("作者信息", user);
        map.put("Gitee", "https://gitee.com/zakrov");
        map.put("NullValueKey", "");
        return new JsonResult<>(map);
    }
}
